<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" media="all" type="text/css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>基本信息</legend>
</fieldset>
<form class="layui-form" action="" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input name="empName" class="layui-input" type="text" placeholder="请输入姓名" autocomplete="off" lay-verify="title">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出生日期</label>
        <div class="layui-input-inline">
            <input name="empBirthdate" class="layui-input" id="date" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input name="empSex" title="男" type="radio" checked="" value="男">
            <input name="empSex" title="女" type="radio" value="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否在职</label>
        <div class="layui-input-block">
            <input name="empWorkstatus" title="在职" type="radio" checked="" value="在职">
            <input name="empWorkstatus" title="离职" type="radio" value="离职">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">证件类型</label>
        <div class="layui-input-block">
            <select name="hrIdent" lay-filter="aihao" id="position" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">证件号</label>
        <div class="layui-input-block">
            <input name="empPapersnum" class="layui-input" type="text" placeholder="请输入证件号" autocomplete="off" lay-verify="sort">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最高学历</label>
        <div class="layui-input-block">
            <select name="empHigthEducation" lay-filter="aihao" id="education" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最高学位</label>
        <div class="layui-input-block">
            <select name="empHigthDegree" lay-filter="aihao" id="degree" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所内身份</label>
        <div class="layui-input-block">
            <select name="empPosition" lay-filter="aihao" id="empPosition" lay-verify="title1" >
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">名族</label>
        <div class="layui-input-block">
            <select name="hrNation" lay-filter="aihao" id="hrNation" lay-verify="title1" >
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">政治面貌</label>
        <div class="layui-input-block">
            <select name="hrPolitical" lay-filter="aihao" id="hrPolitical" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">婚姻状况</label>
        <div class="layui-input-block">
            <select name="empMaritalsta" lay-filter="aihao" id="empMaritalsta" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">门禁号</label>
        <div class="layui-input-block">
            <input name="empEntrancenum" class="layui-input" type="text" placeholder="请输入门禁号" autocomplete="off" lay-verify="sort">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">专业部</label>
        <div class="layui-input-block">
            <select name="hrSpecialty" lay-filter="aihao" id="hrSpecialty" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>从业资料</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">执业类别</label>
        <div class="layui-input-block">
            <select name="hrPractise" lay-filter="aihao" id="hrPractise" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职业证号码</label>
        <div class="layui-input-block">
            <input name="empPracnum" class="layui-input" type="text" placeholder="请输入号码" autocomplete="off" lay-verify="sort">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">首职业时间</label>
        <div class="layui-input-inline">
            <input name="empPracdate" class="layui-input" id="date1" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">首次职业地</label>
        <div class="layui-input-block">
            <input name="empPracsite" class="layui-input" type="text" placeholder="请输入地点" autocomplete="off" lay-verify="title">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资格证类别</label>
        <div class="layui-input-block">
            <select name="hrCertify" lay-filter="aihao" id="hrCertify" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资格证号码</label>
        <div class="layui-input-block">
            <input name="empCertifynum" class="layui-input" type="text" placeholder="请输入号码" autocomplete="off" lay-verify="sort">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资格证考取方式</label>
        <div class="layui-input-block">
            <select name="empGainway" lay-filter="aihao" id="empGainway" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资格证考取地</label>
        <div class="layui-input-block">
            <input name="empGainsite" class="layui-input" type="text" placeholder="请输入地点" autocomplete="off" lay-verify="title">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">个人介绍</label>
        <div class="layui-input-block">
            <textarea name="empIntroduce" class="layui-textarea" placeholder="请输入内容"></textarea>
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>入职情况</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">入职日期</label>
        <div class="layui-input-inline">
            <input name="empEntryDate" class="layui-input" id="date2" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">社保号码</label>
        <div class="layui-input-block">
            <input name="empSocialNum" class="layui-input" type="text" placeholder="请输入号码" autocomplete="off" lay-verify="sort">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合同开始</label>
        <div class="layui-input-inline">
            <input name="empContStartdate" class="layui-input" id="qBeginTime" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合同截止</label>
        <div class="layui-input-inline">
            <input name="empContEnddate" class="layui-input" id="qEndTime" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否参保</label>
        <div class="layui-input-block">
            <input name="empInsured" title="是" type="radio" checked="" value="是">
            <input name="empInsured" title="否" type="radio" value="否">
           </div>
           <div class="layui-form-item">
               <label class="layui-form-label">上传头像</label>
               <div class="layui-input-inline uploadHeadImage">
                   <div class="layui-upload-drag" id="headImg">
                       <i class="layui-icon"></i>
                       <p>点击上传图片，或将图片拖拽到此处</p>
                   </div>
               </div>
                   <div class="layui-input-inline">
                       <div class="layui-upload-list">
                           <img class="layui-upload-img headImage" src="" id="demo1">
                           <p id="demoText"></p>
                       </div>
                   </div>
           </div>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1">
                <p id="demoText"></p>
                    <input name="empPicture" id="empPicture" type="hidden">
            </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>联系信息</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-block">
            <input name="empPhone" class="layui-input" type="text" placeholder="请输入号码" lay-verify="phone" autocomplete="off">
        </div>
    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系地址</label>
            <div class="layui-input-block">
                <input name="empSite" class="layui-input" type="text" placeholder="请填写地址" autocomplete="off" lay-verify="title">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input name="empContactPhone" class="layui-input" type="text" placeholder="请输入电话" autocomplete="off" lay-verify="phone">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input name="empEmail" class="layui-input" type="text" placeholder="请填写邮箱" autocomplete="off" lay-verify="email">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮政编码</label>
            <div class="layui-input-block">
                <input name="empPostcode" class="layui-input" type="text" placeholder="请填写邮政编码" autocomplete="off" lay-verify="title">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">QQ</label>
            <div class="layui-input-block">
                <input name="empQq" class="layui-input" type="text" placeholder="请输入号码" autocomplete="off" lay-verify="sort">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">微信</label>
            <div class="layui-input-block">
                <input name="empWechat" class="layui-input" type="text" placeholder="请输入号码" autocomplete="off" lay-verify="title">
            </div>
        </div>
        <input type="hidden" name="empState" value="1">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="submit" lay-filter="demo2" lay-submit="">立即提交</button>
        </div>
    </div>
</form>
<script src="../../layuiadmin/layui-v2.5.5/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript" src="../../layuiadmin/lib/jquery.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate','upload'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#date2'
        });
        laydate.render({
            elem: '#date3'
        });
        laydate.render({
            elem: '#date4'
        });
    laydate.render({	elem: '#qBeginTime',	format: 'yyyy-MM-dd',	done: function (value, date, endDate) {		var startDate = new Date(value).getTime();		var endTime = new Date($('#qEndTime').val()).getTime();		if (endTime < startDate) {			layer.msg('结束时间不能小于开始时间');			$('#qBeginTime').val($('#qEndTime').val());		}	}	})
       laydate.render({elem: '#qEndTime',	format: 'yyyy-MM-dd',	done: function (value, date, endDate) {		var startDate = new Date($('#qBeginTime').val()).getTime();		var endTime = new Date(value).getTime();		if (endTime < startDate) {			layer.msg('结束时间不能小于开始时间');			$('#qEndTime').val($('#qBeginTime').val());		}	}})



                var uploadInst = upload.render({
                    elem: '#headImg'
                    , url: 'http://localhost:8080/upload/headImg'
                    , size: 500
                    , before: function (obj) {
                        //预读本地文件示例，不支持ie8
                        obj.preview(function (index, file, result) {
                            $('#demo1').attr('src', result); //图片链接（base64）
                        });
                    }
                    , done: function (res) {
                        //如果上传失败
                        if (res.code > 0) {
                            return layer.msg('上传失败');
                        }
                        //上传成功
                        //打印后台传回的地址: 把地址放入一个隐藏的input中, 和表单一起提交到后台, 此处略..
                        /*   console.log(res.data.src);*/
                        // window.parent.uploadHeadImage(res.data.src);
                        var demoText = $('#demoText');
                        // demoText.html('<span style="color: #8f8f8f;">上传成功!!!</span>');
                        $("#empPicture").val(res.data);//
                    }
                    , error: function () {
                        //演示失败状态，并实现重传
                        var demoText = $('#demoText');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                        demoText.find('.demo-reload').on('click', function () {
                            uploadInst.upload();
                        });
                    }
                });
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 1){
                    return '请输入';
                }
            }
            ,title1: function(value){
                if(value.length < 1){
                    return '请选择';
                }
            }
            ,phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
            ,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
            ,sort:[/^$|^[0-9]{0,5}$/,'必须是数字']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        //证件类型
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/certificate.json",
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#position').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
        //最高学历
        $(function(){
            $.ajax({
                type:"POST",
                url:"http://localhost:8080/HrEmp/education",
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#education').append("<option value="+item.educationName+">"+item.educationName+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
        //最高学位
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/degree.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#degree').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
        //身份
        $(function(){
            $.ajax({
                type:"POST",
                url:"http://localhost:8080/HrEmp/position",
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#empPosition').append("<option value="+item.hrPositionName+">"+item.hrPositionName+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //名族
        $(function(){
            $.ajax({
                type:"POST",
                url:"http://localhost:8080/HrEmp/nation",
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#hrNation').append("<option value="+item.nationName+">"+item.nationName+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //政治面貌
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/politics.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#hrPolitical').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //婚姻状况
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/marriage.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#empMaritalsta').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //专业部
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/technical.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#hrSpecialty').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //职业类别
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/operation.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#hrPractise').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //资格证类别
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/hrCertify.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#hrCertify').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //资格证考取方式
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/empGainway.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#empGainway').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        });
        //监听提交
        form.on('submit(demo2)', function(data){
            $.ajax({
                type:"POST",
                url:"http://localhost:8080/HrEmp/add",
                data:data.field,
                datatype:"json",
                async:true,
                success:function(data){
                    layer.alert('添加成功',function(){
                        parent.layer.closeAll();
                    })
                    parent.layui.table.reload('listData')
                },error:function(){
                    alert("失败")
                }
            });
            return false;
/*            layer.alert(JSON.stringify(data.field), {

                title: '最终的提交信息'
            })
            return false;*/
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>